package com.he.hsdyc.controller;

import com.he.hsdyc.config.Queue.DelaySender;
import com.he.hsdyc.model.Order;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value="AmqpController",description="amqp测试",tags={"amqp测试"})
@RestController
@RequestMapping("amqp")
public class TestAmqpContorller {

    @Autowired
    private DelaySender delaySender;

    @GetMapping("/sendDelay")
    public Object sendDelay() {
        Order order1 = new Order();
        order1.setOrderStatus(0);
        order1.setOrderId("123456");
        order1.setOrderName("小米6");

        //测试mq发送实时消息
        delaySender.sendNow(order1);
        //测试mq发送延时消息
        delaySender.sendDelay(order1);
        return "ok";
    }
}
//启动时需要将mq队列，路由相关（AMQPConfig）以bean的形式注册到spring容器中去，
//发送时可根据情况选择发送实时消息还是延时消息，接收时只监听正常队列
//延时消息首先会进入死信队列，待ttl过期后会根据绑定的规则自动转发到正常队列中去，从而被消费，
//在被消费时可根据自己的业务逻辑做相应的判断，如判断订单的支付状态，若未支付则删除该订单